#pragma once
#ifndef _VIDEO_MPP_H_
#define _VIDEO_MPP_H_

#include <rk_mpi.h>

#define VIDEO_MAX_SIZE 65500   // 此时的是H264的MAX大小
#define MPP_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))

// #define MPP_OUTPUT_TEST

struct ctx_mpp_enc_data
{
    // global flow control flag
    uint32_t frm_eos;
    uint32_t pkt_eos;
    uint32_t frame_count;
    uint64_t stream_size;

    // base flow context
    MppCtx ctx;
    MppApi *mpi;
    MppEncPrepCfg prep_cfg;
    MppEncRcCfg rc_cfg;
    MppEncCodecCfg codec_cfg;

    // input / output
    MppBuffer frm_buf;
    MppEncSeiMode sei_mode;

    uint32_t width;
    uint32_t height;
    uint32_t hor_stride;
    uint32_t ver_stride;
    MppFrameFormat fmt;
    MppCodingType type;
    uint32_t num_frames;

    // resources
    size_t frame_size;

    int32_t gop;
    int32_t fps;
    int32_t bps;
#ifdef MPP_OUTPUT_TEST
    FILE *fp_output; // output tmp
#endif
};

class cls_video_mpp
{
public:
    cls_video_mpp(cls_video *p_video);
    ~cls_video_mpp();

    void encode_image(ctx_image_data *image_data); // encode yuv422 --> h264 and add to video_queue

private:
    cls_video *video;

    ctx_mpp_enc_data mpp_enc_data;

    void init_mpp();
    void distory_mpp();
};

#endif